package cn.itcast.bos.mq;

import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.MessageListener;

import org.springframework.stereotype.Service;

import cn.itcast.bos.utils.MailUtils;

@Service("mailConsumer")
public class MailConsumer implements MessageListener {

	@Override
	public void onMessage(Message message) {
		MapMessage mapMessage = (MapMessage) message;
		try {
			String subject = mapMessage.getString("subject");
			String content1 = mapMessage.getString("content1");
			String content3 = mapMessage.getString("content3");
			String content = content1 + MailUtils.activeUrl + content3;
			String mail = mapMessage.getString("mail");
			MailUtils.sendMail(subject, content, mail);
			System.out.println("邮件发送成功," + mail);
		} catch (JMSException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
